import { createSlice } from "@reduxjs/toolkit";
// import type { PayloadAction } from "@reduxjs/toolkit";
import { User } from "@/modules/login";
export interface CounterState {
  value: User;
}

const initialState: CounterState = {
  value: {
    id: 0,
    username: "",
    phone: "",
    nickname: "",
    gender: 0,
    role: "",
    token: "",
    headImg: "",
  },
};

export const counterSlice = createSlice({
  name: "counter",
  initialState,
  reducers: {
    set: (state, etet) => {
      // Redux Toolkit allows us to write "mutating" logic in reducers. It
      // doesn't actually mutate the state because it uses the Immer library,
      // which detects changes to a "draft state" and produces a brand new
      // immutable state based off those changes

      state.value = etet.payload;
      // state.value = etet.payload.value;
    },
    // get: (state, e) => {
    //   console.log(state);
    //   console.log(e);
    // },
    // incrementByAmount: (state, action: PayloadAction<number>) => {
    //   // state.value += action.payload;
    // },
  },
});

// Action creators are generated for each case reducer function
// incrementByAmount;
export const { set} = counterSlice.actions;

export default counterSlice.reducer;
